using Microsoft.AspNetCore.Mvc;
using ZR.Model.FacManage.Dto;
using ZR.Model.FacManage;
using ZR.Service.FacManage.IFacManageService;
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using Aliyun.OSS;
using ZR.Service.FacManage;

//创建时间：2025-03-30
namespace ZR.Admin.WebApi.Controllers.FacManage
{
    /// <summary>
    /// 车间管理
    /// </summary>
    [Verify]
    [Route("FacManage/FacWorkshop")]
    public class FacWorkshopController : BaseController
    {
        /// <summary>
        /// 车间管理接口
        /// </summary>
        private readonly IFacWorkshopService _FacWorkshopService;

        public FacWorkshopController(IFacWorkshopService FacWorkshopService)
        {
            _FacWorkshopService = FacWorkshopService;
        }

        /// <summary>
        /// 查询车间管理列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("pageList")]
        [ActionPermissionFilter(Permission = "fac:workshop:list")]
        public IActionResult PageFacWorkshop([FromQuery] FacWorkshopQueryDto parm)
        {
            var response = _FacWorkshopService.GetPageList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 获取车间树信息
        /// </summary>
        /// <param name="disabledFactory">禁用工厂选择</param>
        /// <returns></returns>
        [HttpGet("treeList")]
        [ActionPermissionFilter(Permission = "fac:workshop:list")]
        public IActionResult TreeFacWorkshop(bool disabledFactory)
        {
            var response = _FacWorkshopService.GetTreeList(disabledFactory);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询车间管理详情
        /// </summary>
        /// <param name="WorkshopId"></param>
        /// <returns></returns>
        [HttpGet("{WorkshopId}")]
        [ActionPermissionFilter(Permission = "fac:workshop:query")]
        public IActionResult GetFacWorkshop(string WorkshopId)
        {
            var response = _FacWorkshopService.GetInfo(WorkshopId);

            var info = response.Adapt<FacWorkshopDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加车间管理
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "fac:workshop:add")]
        [Log(Title = "车间管理", BusinessType = BusinessType.INSERT)]
        public IActionResult AddFacWorkshop([FromBody] FacWorkshopDto parm)
        {
            var modal = parm.Adapt<FacWorkshop>().ToCreate(HttpContext);

            var response = _FacWorkshopService.AddFacWorkshop(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新车间管理
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "fac:workshop:edit")]
        [Log(Title = "车间管理", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateFacWorkshop([FromBody] FacWorkshopDto parm)
        {
            var modal = parm.Adapt<FacWorkshop>().ToUpdate(HttpContext);
            var response = _FacWorkshopService.UpdateFacWorkshop(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除车间管理
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete")]
        [ActionPermissionFilter(Permission = "fac:workshop:delete")]
        [Log(Title = "车间管理", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteFacWorkshop([FromBody] string[] ids)
        {
            var response = _FacWorkshopService.DeleteFacWorkshop(ids);
            return ToResponse(response);
        }

    }
}